<template>
	<div class="middle">
		<div class="middlebg"></div>
		<div class="top">
			<span class="teacher">教案管理 <i class="el-icon-arrow-right"></i></span>
			<router-link to="../createLesson">
			<span class="addteacher"><i class="el-icon-plus"></i>创建教案</span>
			</router-link>
			<span class="back" @click="back">返回</span>
		</div>
		<el-card class="box-card" v-loading="loading" element-loading-background="rgba(255,255,255, 0.5)">
			<div slot="header" class="clearfix card">
				<!--搜索区域-->
				<div>
					学年<template>
						  <el-select class="class" v-model="yearId" clearable placeholder="请选择学年">
							  <el-option v-for="item in yearOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						  </el-select>
						</template>
					班级<template>
						  <el-select class="class" v-model="classId" clearable placeholder="请选择班级">
							  <el-option v-for="item in classOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						  </el-select>
						</template>
					教材类别<template>
            <el-select class="class" v-model="categoryId" clearable placeholder="请选择教材类型">
              <el-option v-for="item in type_title" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
						</template>
					<el-button type="danger" class="btn" @click="search">搜索</el-button>
					<form class="form">
					  <input type="file" name="fileup" id="uploadEventFile" v-on:change="fileChange($event)" style="display:none" />
					</form>
				</div>
				<!--表格区域-->
				<el-table ref="singleTable" :data="teacherPlanInfo" highlight-current-row style="width: 100%">
					<el-table-column property="motion" label="教案名称" width="280" align="center"></el-table-column>
					<el-table-column property="gradeClass" label="上课班级" width="120" align="center"></el-table-column>
					<el-table-column property="year" label="学年" width="100" align="center"></el-table-column>
					<el-table-column property="class_hour" label="课时" width="100"align="center"> </el-table-column>
					<el-table-column property="teacher" label="老师" width="100"align="center"> </el-table-column>
					<el-table-column label="操作" align="center">
						<template slot-scope="scope">
							<el-button @click="edit(scope.row.id)" type="primary" plain size="mini">编辑</el-button>
							<el-button @click="del(scope.row.id)" type="success" plain size="mini">删除</el-button>
							<el-button @click="Export(scope.row.id)" type="danger" plain size="mini">导出</el-button>
						</template>
					</el-table-column>
				  </el-table>
				<!--分页功能-->
				<el-pagination
				   class="fenye"
				   @size-change="SizeChange"
				   @current-change="currentChange"
				   :current-page="page"
				   :page-sizes="pagesizes"
				   :page-size="rows"
				   layout="total, sizes, prev, pager, next, jumper"
				   :total="total"
				   >
				</el-pagination>
			</div>
		</el-card>
	</div>
</template>

<script>
	export default {
		data(){
			return {
				loading:false,//加载
				yearOptions:[],
				yearId:'',//学年id
				classOptions:[],
				classId:'',//班级id
				type_title:[],
				categoryId:'',//教材类别id
				//教案表
				teacherPlanInfo:[],//首页信息
				rows:6,//每页几条
				page:1,//当前显示页数
				pagesizes:[6,10,15,20],//更改每页显示条数
				total:20,//一共多少条,
			}
		},
		methods:{
			//获取教案管理首页内容
			getTeacherPlanInfo(){
				this.$http.post('/api/t_plan/getTeacherPlan',{
					rows:this.rows,
					page:this.page,
					school_year_id:this.yearId,
					grade_class_id:this.classId,
					plan_type_id:this.categoryId
				}).then(res=>{
					this.teacherPlanInfo = res.data.data
					this.teacherPlanInfo.map(item=>{
						if(item.get_grade_class == null) {
							item.gradeClass = item.get_grade.grade_title
						}else {
							item.gradeClass = item.get_grade.grade_title + item.get_grade_class.class_name
						}
						if(item.get_school_year == null){
							item.year = ''
						}else {
							item.year = item.get_school_year.section
						}
						item.teacher = item.get_teacher.teacher_name
					})
					this.total = res.data.count
				})
			},
			//每页显示条数
			SizeChange(val){
				this.rows = val
				this.getTeacherPlanInfo()
			},
			//切换第几页
			currentChange(val){
			  	this.page = val
			  	this.getTeacherPlanInfo()
			},
			//返回上一页
			back(){
				this.$router.push({name:'teaching'})
			},
			//获取搜索信息
			getSearchInfo(){
				this.$http.post('/api/teacher_plan/getSearchInfo')
					.then(res=>{
						res.data.year.map(item =>{
							var obj ={}
							obj.label = item.year
							obj.value = item.id
							this.yearOptions.push(obj)
						})
						res.data.type_title.map(item =>{
							var obj ={}
							obj.label = item.title
							obj.value = item.id
							this.type_title.push(obj)
						})
						res.data.grade_class_info.map(item=>{
							var obj ={}
							obj.label = item.get_grade.grade_title + item.class_name
							obj.value = item.id
							this.classOptions.push(obj)
						})
					})
			},
			//搜索功能
			search(){
				this.getTeacherPlanInfo()
			},
			//删除功能
			del(id){
				this.$confirm('是否永久删除, 是否继续?', '提示', {
			      confirmButtonText: '确定',
			      cancelButtonText: '取消',
			      type: 'warning'
			    }).then(() => {
			    	this.$http.post('/api/t_plan/deleteTeacherPlan', {
			    		id:id
			    	}).then(res=>{
			    		this.getTeacherPlanInfo()
						if(res.data.code== 200){
							this.$message({
							  type: 'success',
							  message: res.data.msg
							});
						}else if (res.data.errorCode == 400) {
							this.$message({
							  type: 'error',
							  message: res.data.msg
							});
						}
			    	})
			    })
			},
			//导出
			Export(id){
				window.location.href="http://pcprograme.tijian121.com/api/template/exportTeacherPlanInfo?id="+id
			},
			//创建教案
			addPlan(){

			},
			//编辑
			edit(id){
				this.$router.push({path:'/editLesson/'+id})
			}
		},
		created(){
			this.getTeacherPlanInfo()
			this.getSearchInfo()
		}
	}
</script>

<style>
	.el-main {
		padding: 0;
	}
	.middle {
	    height: 100%;
	    width: 100%;
	    background-repeat:repeat;
	    background-size: contain;
	    background-position: center;
	    background-attachment: fixed;
	    z-index: -1;
	}
	.el-dialog__body {
		padding: 0px 20px;
	}
</style>
<style lang="less" scoped>
	.middlebg {
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
		width: 100%;
		height: 100%;
		background: url(../../assets/image/bg-img.png) no-repeat center;
		background-size: 100%;
	}
	.top {
		height: 50px;
		line-height: 50px;
		background-color: #dbdbdb;
		position: relative;
		.teacher {
			display: inline-block;
			background: #00b02d;
			padding:0 15px;
			color: #fff;
		}
		.addteacher {
			display: inline-block;
			background: #3A8EE6;
			height: 24px;
			line-height: 24px;
			position: absolute;
			right: 180px;
			top: 10px;
			padding: 3px 15px;
			font-size: 14px;
			border-radius: 5px;
			color: #fff;
			cursor: pointer;
		}
		.back {
			position: absolute;
			right: 0;
			background: #9cbf83;
			padding: 0 15px;
			border-radius: 3px;
			color: #fff;
			cursor: pointer;
		}
	}
	.box-card{
		margin: 30px 50px;
		.card {
			padding: 20px;
		}
		.class {
			width: 180px;
			margin: 0 5px 0 5px;
		}
		.btn {
			width: 70px;
			height: 40px;
			margin-left: 30px;
		}
		.fenye {
			margin-top: 20px;
			text-align: center;
		}
	}
</style>
